<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
    <title>添加年排产单(作废)</title>
</head>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-header">滚动生产排产表</div>
                
                <table class="layui-hide" id="test" lay-filter="test"></table>
                
                 <form class="layui-form layui-card-body" action="${pageContext.request.contextPath }/year/createYear.do">
                   <div class="layui-form-item">
				    <div class="layui-inline">
				      <label class="layui-form-label">编制</label>
				      <div class="layui-input-inline">
				        <input type="tel" name="maker" autocomplete="off" class="layui-input">
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">审核</label>
				      <div class="layui-input-inline">
				        <input type="tel" name="approval" autocomplete="off" class="layui-input">
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">技术部查收</label>
				      <div class="layui-input-inline">
				        <input type="tel" name="jcheck" autocomplete="off" class="layui-input">
				      </div>
				    </div>
				    <div class="layui-inline">
				      <label class="layui-form-label">综合部查收</label>
				      <div class="layui-input-inline">
				        <input type="tel" name="zcheck" autocomplete="off" class="layui-input">
				      </div>
				    </div>
				  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block" style="float: right;">
                      <button class="layui-btn layui-btn-blue" lay-submit lay-filter="save" id="save">立即提交</button>
                      <button type="button" class="layui-btn layui-btn-primary"  onclick="back()">返回</button>
                    </div>
                  </div>
                </form>  
            </div>
        </div>
    </div>
<p>
    <br/>
</p>
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>

<script type="text/javascript">
function back() {
	window.location.href="${pageContext.request.contextPath }/year/sheduYear.do";
}
</script>

<script>
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	table.render({
	    elem: '#test'
	    ,url:'${pageContext.request.contextPath }/year/selectList.do'
	    ,title: '年生产排产表'
	    ,id :'contenttable'
	    ,cols: [[
	      {type: 'checkbox', fixed: 'left'}
	      //,{field:'id', title:'id'}
	      ,{field:'sub', title:'组件编码（支）', width:200}
	      ,{field:'jan', title:'1月', edit: 'text', width:100}
	      ,{field:'feb', title:'2月', edit: 'text', width:100}
	      ,{field:'mar', title:'3月', edit: 'text', width:100}
	      ,{field:'apr', title:'4月', edit: 'text', width:100}
	      ,{field:'may', title:'5月', edit: 'text', width:100}
	      ,{field:'jun', title:'6月', edit: 'text', width:100}
	      ,{field:'jul', title:'7月', edit: 'text', width:100}
	      ,{field:'aug', title:'8月', edit: 'text', width:100}
	      ,{field:'sept', title:'9月', edit: 'text', width:100}
	      ,{field:'oct', title:'10月', edit: 'text', width:100}
	      ,{field:'nov', title:'11月', edit: 'text', width:100}
	      ,{field:'dec', title:'12月', edit: 'text', width:100}
	    ]]
	    ,done: function(res, curr, count){
	    	$("[data-field='id']").css('display','none');
	    	}
	});
  
	
	 //监听单元格编辑
	  table.on('edit(test)', function(obj){
	    var value = obj.value //得到修改后的值
	    ,data = obj.data //得到所在行所有键值
	    ,field = obj.field; //得到字段
	    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
	    
	    $.ajax({
	    	type:'post',
	    	url:'${pageContext.request.contextPath }/year/createDetail.do',
	    	data: ""+field+"=" + value + "&sub=" + data.sub,
	    	success:function(data){
	    		if(data>0){
	    			toastr.success("添加成功！");
	    		}else{
	    			toastr.warning("添加失败！");
	    		}
	    	}
	    })
	  });
	 
	 //表单提交
	form.on('submit(save)', function(data) {
	  var datas=data.field;
	  var action=data.form.action;
	  $.ajax({
		  url:action,
		  data:datas,
		  type:"POST",
		  dataType:"json",
		  success:function(result){
			 if(result > 0) {
				toastr.success("添加成功！");
				setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					window.location.href="${pageContext.request.contextPath }/year/sheduYear.do";
				},2000);
			 }else {
				 toastr.warning("添加失败！");
				 return false;
			 }
		  },
	  });
	  
	  return false;
	});
	 
});
toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>